#ifdef HAVE_SYS_RESOURCE_H
#include <sys/resource.h>
#endif
+#include "shell-jsapi-compat-private.h"
#define SHELL_DBUS_SERVICE "org.gnome.Shell"
#define MAGNIFIER_DBUS_SERVICE "org.gnome.Magnifier"
JSContext *context = gjs_context_get_native_context (global->js_context);
char *search_path[2] = { 0, 0 };
+ JS_BeginRequest (context);
+
// This is a bit of a hack; ideally we'd be able to pass our target
// object directly into this function, but introspection doesn't
// support that at the moment. Instead evaluate a string to get it.
G_IO_ERROR_FAILED,
"%s", message ? message : "(unknown)");
g_free(message);
- return FALSE;
+ goto out_error;
}
if (!JSVAL_IS_OBJECT (target_object))
{
g_error ("shell_global_add_extension_importer: invalid target object");
- return FALSE;
+ goto out_error;
}
search_path[0] = (char*)directory;
importer = gjs_define_importer (context, JSVAL_TO_OBJECT (target_object), target_property, (const char **)search_path, FALSE);
+ JS_EndRequest (context);
return TRUE;
+ out_error:
+ JS_EndRequest (context);
+ return FALSE;
}
/* Code to close all file descriptors before we exec; copied from gspawn.c in GLib.
jsuint attrs;
JSBool found;
- JS_AddRoot (context, &val);
+ JS_BeginRequest (context);
+ JS_AddValueRoot (context, &val);
parts = g_strsplit (object, ".", -1);
obj = JS_GetGlobalObject (context);
if (!JS_GetProperty (context, obj, parts[i], &val))
{
g_strfreev (parts);
- JS_RemoveRoot (context, &val);
- gjs_log_exception (context, NULL);
- return FALSE;
+ goto out_error;
}
obj = JSVAL_TO_OBJECT (val);
}
g_strfreev (parts);
if (!JS_GetPropertyAttributes (context, obj, property, &attrs, &found) || !found)
- {
- JS_RemoveRoot (context, &val);
- gjs_log_exception (context, NULL);
- return FALSE;
- }
+ goto out_error;
if (mutable)
attrs &= ~(JSPROP_PERMANENT | JSPROP_READONLY);
else
attrs |= (JSPROP_PERMANENT | JSPROP_READONLY);
- JS_SetPropertyAttributes (context, obj, property, attrs, &found);
+ if (!JS_SetPropertyAttributes (context, obj, property, attrs, &found))
+ goto out_error;
- JS_RemoveRoot (context, &val);
- return !gjs_log_exception (context, NULL);
+ JS_RemoveValueRoot (context, &val);
+ JS_EndRequest (context);
+ return TRUE;
+ out_error:
+ gjs_log_exception (context, NULL);
+ JS_RemoveValueRoot (context, &val);
+ JS_EndRequest (context);
+ return FALSE;
}
typedef struct
--- /dev/null
+/* -*- mode: C; c-file-style: "gnu"; indent-tabs-mode: nil; -*- */
+/*
+ * shell-jsapi-compat.h: Compatibility wrapper for older Spidermonkey
+ *
+ * Copyright 2010 Red Hat, Inc.
+*
+ * This program is free software; you can redistribute it and/or modify it
+ * under the terms and conditions of the GNU Lesser General Public License,
+ * version 2.1, as published by the Free Software Foundation.
+ *
+ * This program is distributed in the hope it will be useful, but WITHOUT ANY
+ * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
+ * FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for
+ * more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public License
+ * along with this program; if not, write to the Free Software Foundation,
+ * Inc., 51 Franklin St - Fifth Floor, Boston, MA 02110-1301 USA.
+ * Boston, MA 02111-1307, USA.
+ *
+ */
+
+#ifndef __SHELL_JSAPI_COMPAT_H__
+#define __SHELL_JSAPI_COMPAT_H__
+
+#include "config.h"
+
+#ifndef HAVE_JS_NEWGLOBALOBJECT
+
+/* The old JS_AddRoot accepted anything via void *, new
+ * api is stricter.
+ */
+#define JS_AddValueRoot JS_AddRoot
+#define JS_AddObjectRoot JS_AddRoot
+#define JS_AddStringRoot JS_AddRoot
+#define JS_AddGCThingRoot JS_AddRoot
+#define JS_RemoveValueRoot JS_RemoveRoot
+#define JS_RemoveObjectRoot JS_RemoveRoot
+#define JS_RemoveStringRoot JS_RemoveRoot
+#define JS_RemoveGCThingRoot JS_RemoveRoot
+
+#endif
+
+#endif